# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-covered
pkgver=0.18.5
pkgrel=1
pkgdesc='A modern approach to code coverage'
arch=(any)
url='https://github.com/ioquatix/covered'
license=(MIT)
depends=(ruby-console ruby-msgpack ruby-parser)
checkdepends=(ruby-rspec ruby-sus ruby-trenni ruby-bake-test ruby-minitest)
options=(!emptydirs)
source=(https://github.com/ioquatix/covered/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('dab270768595961e4a59d7ed9a73173eccd62b87b9988acf8071e2b35972c867')

prepare() {
  cd covered-$pkgver
  sed -e 's/~>/>=/' -e '/signing_key/d' -i covered.gemspec
  sed -i '/bake-modernize/d;/bake-gem/d;/bake-github-pages/d;/utopia-project/d' gems.rb
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd covered-$pkgver
  gem build covered.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    covered-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd covered-$pkgver
  GEM_HOME="tmp_install/$_gemdir" bake test
}

package() {
  cd covered-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 license.md -t "$pkgdir"/usr/share/licenses/$pkgname/
}
